import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws FileNotFoundException {
		Scanner scanner = new Scanner(new File(args[0]));
		
		ArrayList<String> lines = new ArrayList<String>();
		
		while (scanner.hasNext())
			lines.add(scanner.nextLine());
		
		scanner.close();
		
		double sup = Double.parseDouble(args[1]);
		double conf = Double.parseDouble(args[2]);
		
		APriori ap = new APriori(lines, ",", sup, conf);
		ap.fillLargeSets();

		System.out.format("==Large itemsets (min_sup=%2.2f%%)\n", sup * 100);
		ap.printLargeSets();

		System.out.println();
		System.out.format(
				"==High-confidence association rules (min_conf=%2.2f%%)\n",
				conf * 100);
		for (Rule rule : ap.getRules())
			System.out.println(rule); 
	}
	
	public static void simpleTest()
	{
		String[] txns = new String[] {
				"ink,pen,diary,soap",
				"pen,ink,diary",
				"pen,diary",
				"pen,ink,soap"
			};

		double sup = 0.5;
		double conf = 0.7;

		APriori ap = new APriori(Arrays.asList(txns), ",", sup, conf);
		ap.fillLargeSets();

		System.out.format("==Large itemsets (min_sup=%2.2f%%)\n", sup * 100);
		ap.printLargeSets();

		System.out.println();
		System.out.format(
				"==High-confidence association rules (min_conf=%2.2f%%)\n",
				conf * 100);
		for (Rule rule : ap.getRules())
			System.out.println(rule);
	}

}
